package com.teemor.tim.utils;

import com.teemor.tim.enums.MessageType;
import com.teemor.tim.model.message.MessageModel;
import com.teemor.tim.model.message.MessageWrapper;
import com.teemor.tim.model.message.TimMessage;

import java.util.ArrayList;
import java.util.List;

/**
 * @ename zhoulk
 * @cname 周李科
 * @date 2020/12/16 14:00
 */
public class MessageUtil {

    public static MessageModel timMessageFormat(TimMessage message) {
        MessageType messageType = MessageType.valOf(message.getMsgType());
        if (messageType == null) return null;
        return new MessageModel(message, messageType);
    }

    public static List<MessageWrapper> messagesFormat(List<? extends MessageWrapper> messages) {
        List<MessageWrapper> result = new ArrayList<>();
        messages.forEach(message -> {
            if (message instanceof TimMessage) {
                result.add(timMessageFormat((TimMessage) message));
            } else if (message instanceof MessageModel) {
                result.add(message);
            }
        });
        return result;
    }

}
